<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
class Timing extends Controller
{
    /**
     * 自营商城的订单相关定时器（1分一跑）
     */
    public function shopOverTime(){
        set_time_limit(0);
        //定时器1：解答超过1小时未提交则清除状态;定时器3：未答题的一小时后关闭
        //1-1：自营订单的超时自动取消
        $today = date('Y-m-d H:i:s');
        $time = time();
        $one_hour_ago = date("Y-m-d H:i:s",($time - 3600*24));
        $where = [];
        $where['s_verify'] = 2;
        $where['s_status'] = 1;
        $where['s_endtime'] = ['<',$today];
        $field = 's_id';
        $res = Db::table('up_shop')
            ->where($where)
            ->field($field)
            ->select();
//        dump($res);die;
        if($res){
            Db::startTrans();
            try{
                foreach ($res as $k => $od){
                    Db::table('up_shop')->where('s_id',$od['s_id'])->update(['s_status' => 3, 's_update_time' => $today]);
                    $have = Db::table('up_shop_image')
                        ->where('si_s_id',$od['s_id'])
                        ->where('si_status',1)
                        ->find();
                    if($have){
                        Db::table('up_shop_image')
                            ->where('si_s_id',$od['s_id'])
                            ->where('si_status',1)
                            ->update([
                                'si_status' => 3 ,
                                'si_update_time' => date('Y-m-d H:i:s')
                            ]);
                    }
                }
                Db::commit();
                return 1;
            }catch (\Exception $e) {
                Db::rollback();
                return 2;
            }
        }
    }
    public function test()
    {
//        $a = 'Qwqw是我啊';
//        $a = strtolower($a);
//        echo $a;
//        die;
//        sentWeChatNotice('oToxI5u7vJDJrC7UliPNPKaNE6z4','测试','跳转到百度试试','http://www.jmjalliance.com/index/server/course.shtml');
    }
}
